package com.docking.heylo.service.impl;

import com.docking.heylo.dao.entity.Dict;
import com.docking.heylo.dao.mapper.DictMapper;
import com.docking.heylo.service.ISysDictService;
import com.docking.heylo.web.dto.AppointmentConfDto;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SysDictServiceImpl implements ISysDictService {

    @Resource
    private DictMapper dictMapper;

    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public void appointmentConf(AppointmentConfDto confDto) {

        // 修改起步价格
        dictMapper.updateByPrimaryKeySelective(new Dict(){{
            setId(2);
            setValue(confDto.getStartingPrice().toString());
        }});

        // 修改精修价格
        dictMapper.updateByPrimaryKeySelective(new Dict(){{
            setId(3);
            setValue(confDto.getRefinedPrice().toString());
        }});

        // 修改平台折扣
        dictMapper.updateByPrimaryKeySelective(new Dict(){{
            setId(4);
            setValue(confDto.getPlatformDiscount().toString());
        }});

        // 修改基础时长
        dictMapper.updateByPrimaryKeySelective(new Dict(){{
            setId(5);
            setValue(confDto.getBaseTime().toString());
        }});

        // 修改超时价格
        dictMapper.updateByPrimaryKeySelective(new Dict(){{
            setId(6);
            setValue(confDto.getOvertimeUnitPrice().toString());
        }});

        dictMapper.updateByPrimaryKeySelective(new Dict(){{
            setId(7);
            setValue(confDto.getRake().toString());
        }});
    }


    @Override
    public Map<String, Object> appointmentConfDetail() {
        List<Map<String, Object>> conf = dictMapper.selectConfByParentName("appointment_conf");
        Map<String, Object> result = new HashMap<>();
        for(Map<String, Object> map : conf){
            result.put(map.get("name").toString(), map.get("value"));
        }
        return result;
    }



}
